package cn.stylefeng.guns.modular.car.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.car.entity.Car;
import cn.stylefeng.guns.modular.car.model.params.CarParam;
import cn.stylefeng.guns.modular.car.service.CarService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 车辆信息控制器
 *
 * @author 
 * @Date 2020-05-10 17:22:07
 */
@Controller
@RequestMapping("/car")
public class CarController extends BaseController {

    private String PREFIX = "/car";

    @Autowired
    private CarService carService;

    /**
     * 跳转到主页面
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/car.html";
    }

    /**
     * 新增页面
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/car_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/car_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(CarParam carParam) {
        this.carService.add(carParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(CarParam carParam) {
        this.carService.update(carParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(CarParam carParam) {
        this.carService.delete(carParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 
     * @Date 2020-05-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(CarParam carParam) {
        Car detail = this.carService.getById(carParam.getSeqId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 
     * @Date 2020-05-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(CarParam carParam) {
        return this.carService.findPageBySpec(carParam);
    }

}


